package com.ccut.xunfeiSpringboot.controller;

import com.ccut.xunfeiSpringboot.common.AjaxResult;
import com.ccut.xunfeiSpringboot.dto.request.CalenderRequest;
import com.ccut.xunfeiSpringboot.entity.CalendarEvent;
import com.ccut.xunfeiSpringboot.service.CalendarEventService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/calendarEvent")
@Slf4j
public class CalendarEventController {

    @Autowired
    private CalendarEventService calendarEventService;

    @PostMapping("/addByAI")
    public void addByAI(@RequestBody CalenderRequest calenderRequest, HttpServletResponse  response) throws Exception {
        calendarEventService.addByAI(calenderRequest.getData(), Integer.valueOf(calenderRequest.getUserId()),response);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody CalendarEvent calendarEvent) {
        calendarEventService.add(calendarEvent);
        return AjaxResult.success();
    }

    @GetMapping("/getAll")
    public AjaxResult getAll(@RequestParam("userId") Integer userId) {
        return AjaxResult.success(calendarEventService.getAll(userId));
    }
}
